package com.ahdy.service.impl;

import com.ahdy.entity.LocationSharing;
import com.ahdy.mapper.LocationSharingMapper;
import com.ahdy.service.LocationSharingService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * 位置共享服务实现类
 */
@Service
public class LocationSharingServiceImpl extends ServiceImpl<LocationSharingMapper, LocationSharing> implements LocationSharingService {
    
    @Autowired
    private LocationSharingMapper locationSharingMapper;
    
    @Override
    public boolean saveLocationSharing(LocationSharing locationSharing) {
        // 设置创建和更新时间
        locationSharing.setCreateTime(LocalDateTime.now());
        locationSharing.setUpdateTime(LocalDateTime.now());
        return save(locationSharing);
    }
    
    @Override
    public LocationSharing getLatestLocationSharing(Integer userId) {
        return locationSharingMapper.selectLatestByUserId(userId);
    }
    
    @Override
    public List<LocationSharing> getLocationSharingHistory(Integer userId, Integer limit) {
        return locationSharingMapper.selectHistoryByUserId(userId, limit);
    }
    
    @Override
    public LocationSharing getLocationSharingByUserAndTarget(Integer userId, Integer targetId) {
        return locationSharingMapper.selectByUserAndTarget(userId, targetId);
    }
} 